<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue-extend</title>
    <link rel="stylesheet" href="../../../assets/css/bootstrap.min.css">
    <script src="../../../assets/js/vue-2.5.6.js"></script>
</head>

<body>
    <div id="app">
        <p>{{ qiwen }}</p>
        <p>
            当前应穿着： {{ wear }}
        </p>
        <btn @click.native="changeWendu(4)"></btn>
        <btn @click.native="changeWendu(-4)"></btn>
    </div>
</body>
<script>
    var btn = {
        template: `<button>改变温度</button>`
    };
    var suggestion = ['T恤短袖', '夹克长裙', '棉衣羽绒服'];
    var app = new Vue({
        el: "#app",
        data: {
            wendu: 10,
            wear: '夹克长裙'
        },
        computed: {
            qiwen: function() {
                return '当前温度：' + this.wendu + '度'
            }
        },
        methods: {
            changeWendu: function(change) {
                return this.wendu += change;
            }
        },
        watch: {
            wendu: function(newVal, oldVal) {
                // alert(newVal);
                if (newVal >= 26) {
                    this.wear = suggestion[0];
                } else if (newVal < 26 && newVal >= 0) {
                    this.wear = suggestion[1];
                } else {
                    this.wear = suggestion[2];
                }
            }
        },
        components: {
            "btn": btn
        }
    })
</script>

</html>